var mainPanel;
Ext.onReady(function() {
	Ext.SSL_SECURE_URL = "resource/ext-3.2.1/resources/images/default/s.gif";
	Ext.BLANK_IMAGE_URL = "resource/ext-3.2.1/resources/images/default/s.gif";
	// Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	Ext.form.Field.prototype.msgTarget = 'side';
	Ext.QuickTips.init();
	var showOnePanel = true;
	mainPanel = new Ext.TabPanel({
		region : 'center',
		deferredRender : false,
		id : 'centerTabPanel',
		activeTab : 0,
		margins : '120 0 0 0',
		// plugins: new Ext.ux.TabCloseMenu(),
		resizeTabs : true,
		minTabWidth : 100,
		tabWidth : 80,
		enableTabScroll : true,
		autoScroll : true,
		items : [{
			margins : '35 5 5 0',
			title : '首页',
			iconCls : 'tabs',
			autoScroll : true,
			html : '<iframe src="index_info.html" width="100%" height="100%"></iframe>'
		}],
		loadPage : function(href, cls, title) {
			var tabId = 'workPanel' + cls;
			var tab = this.getComponent(tabId);
			if (showOnePanel) {
				tabId = 'workPanel';
				tab = this.getComponent(tabId);
				if (tab) {
					this.setActiveTab(tab);
					Ext.get('iframe-workPanel').dom.src = href;
				} else {
					var pIn1 = this.add(new DocPanel({
						id : tabId,
						cclass : cls,
						layout : 'fit',
						items : [new IFrameComponent({
							id : tabId,
							url : href
						})],
						 title: title,
						iconCls : 'tabs'
					}));
					this.setActiveTab(pIn1);
				}
			} else {
				if (tab) {
					this.setActiveTab(tab);
				} else {
					var autoLoad = {
						url : href,
						scripts : true
					};
					var p = this.add(new DocPanel({
						id : tabId,
						cclass : cls,
						layout : 'fit',
						items : [new IFrameComponent({
							id : tabId,
							url : href
						})],
						title : title,
						iconCls : 'tabs'
					}));
					this.setActiveTab(p);
				}
			}
		}
	});

	IFrameComponent = Ext.extend(Ext.BoxComponent, {
		onRender : function(ct, position) {
			this.el = ct.createChild({
				tag : 'iframe',
				id : 'iframe-' + this.id,
				frameBorder : 0,
				src : this.url
			});
		}
	});

	DocPanel = Ext.extend(Ext.Panel, {
		closable : true,
		autoScroll : true,
		initComponent : function() {
			DocPanel.superclass.initComponent.call(this);
		},
		scrollToMember : function(member) {
			var el = Ext.fly(this.cclass + '-' + member);
			if (el) {
				var top = (el.getOffsetsTo(this.body)[1])
						+ this.body.dom.scrollTop;
				this.body.scrollTo('top', top - 25, {
					duration : .75,
					callback : this.hlMember.createDelegate(this, [member])
				});
			}
		},
		scrollToSection : function(id) {
			var el = Ext.getDom(id);
			if (el) {
				var top = (Ext.fly(el).getOffsetsTo(this.body)[1])
						+ this.body.dom.scrollTop;
				this.body.scrollTo('top', top - 25, {
					duration : .5,
					callback : function() {
						Ext.fly(el).next('h2').pause(.2).highlight('#8DB2E3', {
							attr : 'color'
						});
					}
				});
			}
		},
		hlMember : function(member) {
			var el = Ext.fly(this.cclass + '-' + member);
			if (el) {
				el.up('tr').highlight('#cadaf9');
			}
		}
	});

	new Ext.Viewport({
		layout : 'border',
		items : [new Ext.BoxComponent({ // raw
			region : 'logo',
			el : 'logo',
			height : 122
		}), mainPanel]
	});
})

function menuCilck(url, cls,  pageText) {
		mainPanel.loadPage(encodeURI(url), cls,
				pageText);
}